/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package radio.sessions;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import radio.entities.Accounts;

/**
 *
 * @author Huu Vinh
 */
@Stateless
public class AccountsFacade extends AbstractFacade<Accounts> {
    @PersistenceContext(unitName = "RadioCabsEJB-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public Accounts login(String Uid, String Pwd) {
        List<Accounts> result = em.createNamedQuery("Accounts.login").setParameter("uid", Uid).setParameter("pwd", Pwd).getResultList();
        if (!result.isEmpty()) {
            return result.get(0);
        } else {
            return null;
        }
    }
    
    public Accounts findbyId(int accId) {
        List<Accounts> result = em.createNamedQuery("Accounts.findByAccId").setParameter("accId", accId).getResultList();
        if (!result.isEmpty()) {
            return result.get(0);
        } else {
            return null;
        }
    }
    
    public AccountsFacade() {
        super(Accounts.class);
    }
    
}
